package it.koutifaris.travianmap.transformation;

import android.test.AndroidTestCase;

public class ToroidTransformationTest extends AndroidTestCase {

	public void testInvalidBounds() throws Exception {
		try {
			new ToroidTransformation(10, -10, -5, 5);
			fail("Invalid coordinates, should have raised an exception.");
		} catch (Exception e) {
			// OK, test passed
		}
	}

	public void testXOrigin() throws Exception {
		ToroidTransformation transformation = new ToroidTransformation(-10, 10, -5, 5);
		double transformed = transformation.transformX(0);
		assertEquals(0, transformed, 0.01);
	}

	public void testXInBouds() throws Exception {
		ToroidTransformation transformation = new ToroidTransformation(-10, 10, -5, 5);
		double transformed = transformation.transformX(9);
		assertEquals(9, transformed, 0.01);
	}

	public void testYOutOfBouds() throws Exception {
		ToroidTransformation transformation = new ToroidTransformation(-10, 10, -5, 5);
		double transformed = transformation.transformY(6);
		assertEquals(-4, transformed, 0.01);
	}

	public void testPositiveBound() throws Exception {
		final double LOW_BOUND = -5;
		final double UPPER_BOUND = 5;

		double transformed = ToroidTransformation.transform(LOW_BOUND, UPPER_BOUND, UPPER_BOUND);
		assertEquals(LOW_BOUND, transformed, 0.01);
	}

	public void testNegativeBound() throws Exception {
		final double LOW_BOUND = -5;
		final double UPPER_BOUND = 5;

		double transformed = ToroidTransformation.transform(LOW_BOUND, UPPER_BOUND, LOW_BOUND);
		assertEquals(LOW_BOUND, transformed, 0.01);
	}
}
